<template>
  <div>
    <PreviewDialog :calculatorSore="calculatorSore" :describeContent="describeContent"
                   :fields="fields"
                   :medicalCalculatorData="medicalCalculatorData"
                   :type="cntFormulaType"
                   ref="preview"/>
    <EditTaskItemDialog :auditLevel="0"
                        :knowledgeLibId="knowledgeLibId"
                        @insertTaskItem="editById"
                        ref="editTaskItemDialog"/>
    <el-container>
      <el-aside :style="{height: taskListHeight + 'px'}">
        <el-scrollbar style="height:100%;">
          <MenuItem :item="item" :key="index" :reorder="false" @change-selection="refreshList"
                    v-for="(item, index) in items">
          </MenuItem>
          <div style="text-align: right;margin-top: 15px">
            <img src="../../../../static/img/folder.png"
                 style="width: 30px; height: 20px; vertical-align: middle;display: inline-block">
            <div class="cursor" style="margin-right: 20px;display: inline-block" v-on:click="showData"><span
              style="color: red"></span>已完成的任务
              <i :class="showIcon"
                 style=" font-size: 20px;font-weight:normal "></i></div>
            <div v-if="showCompleteData">
              <MenuItem v-for="(item, index) in taskCompleteData" :key="index" :item="item" :reorder="false"
                        @change-selection="refreshFinishList">
              </MenuItem>
            </div>
          </div>
        </el-scrollbar>
      </el-aside>
      <el-container>
        <el-main style="padding: 0px 10px; ">
          <div style="height: 100%;background-color:white">
            <el-row>
              <el-col :span="5">
                <el-button :style="{ display: newEnable }" @click="newTaskItem" size="small"
                           type="success">新建知识
                </el-button>
                <el-button :style="{ display: batchEnable }" @click="batchSubmit" size="small"
                           style="margin:0px"
                           type="success">批量提交
                </el-button>
                <div style="display: inline-block">
                  <div style="display: inline-block"><span></span></div>
                </div>
              </el-col>
              <el-col :span="11" style="text-align: center">
                <el-radio-group @change="valueChange()" size="small" v-model="radioStatus">
                  <el-radio-button label="">全部</el-radio-button>
                  <el-radio-button :style="{ display: statusEnable }" label="0">未提交</el-radio-button>
                  <el-radio-button :style="{ display: statusEnable }" label="underReview">审核中</el-radio-button>
                  <el-radio-button label="2">审核通过</el-radio-button>
                  <el-radio-button :style="{ display: statusEnable }" label="3">未通过</el-radio-button>
                  <el-radio-button :style="{ display: statusReleasedEnable }" label="8">已发布</el-radio-button>
                </el-radio-group>
              </el-col>
              <el-col :span="8">
                <div>
                  <div style="width: 350px; float: right">
                    <el-input @keyup.enter.native="searchEnterFun($event)"
                              placeholder="请输入名称"
                              size="small" v-model="name">
                      <i class="el-input__icon el-icon-search"
                         slot="prefix"></i>
                      <el-button :icon="appendIcon"
                                 slot="append"
                                 v-on:click="switchAppend"></el-button>
                    </el-input>
                  </div>
                  <div
                    id="advance"
                    style="padding: 10px; float: right;" v-if="showAdvance">
                    <div>
                      <div style="width: 90px;text-align:right; display: inline-block;margin-top: 10px">
                        任务类型:
                      </div>
                      <div style="display: inline-block">
                        <el-select clearable size="small" style="width: 300px"
                                   v-model="taskType">
                          <el-option
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                            v-for="item in CONST.TASK_ITEM_STATUS_VO"
                          >
                          </el-option>
                        </el-select>
                      </div>
                    </div>
                    <div v-if="drugInfoLibStatus">
                      <div style="width: 90px;text-align:right; display: inline-block;margin-top: 20px">
                        厂家:
                      </div>
                      <div style="display: inline-block; width:300px;">
                        <el-input v-model="drugInfoLibCompany"
                                  placeholder="请输入厂家"></el-input>
                      </div>
                    </div>
                    <div style="margin-top: 30px; right: 10px;">
                      <el-row>
                        <el-col :offset="6" :span="6">
                          <div style="margin-left: 90px;height: 32px; width: 88px;">
                            <el-button size="small" v-on:click="advanceCancel">取 消
                            </el-button>
                          </div>
                        </el-col>
                        <el-col :offset="2" :span="2">
                          <div style="margin-left: 30px;height: 32px; width: 88px;">
                            <el-button size="small" v-on:click="reset">重置</el-button>
                          </div>
                        </el-col>
                        <el-col :offset="2" :span="2">
                          <div style="margin-left: 30px;height: 32px; width: 88px;">
                            <el-button size="small" type="success"
                                       v-on:click="advanceConfirm">确 定
                            </el-button>
                          </div>
                        </el-col>
                      </el-row>
                    </div>
                  </div>
                </div>
              </el-col>
            </el-row>
            <div :style="{ display: uploadEnable }">
              <div style="margin-top: 10px">
                <el-button plain size="small" type="success"
                           v-on:click="uploadFile()">下载附件
                </el-button>
                <div class="inline-block">开始时间：</div>
                <span style="font-size:14px ">{{ startTime }}</span>
                <div class="inline-block">结束时间：</div>
                <span style="font-size:14px">{{ endTime }}</span>
                <div :style="{ display: totalEnable }" class="inline-block">
                  知识条目：<span>{{ totalNum }}</span></div>
              </div>
            </div>
            <el-row style="margin-top: 10px;">
              <el-col :span="24">
                <el-table highlight-current-row :data="tableData" :height="tableHeight" border>
                  <el-table-column label="序号"
                                   width="50" type="index">
                  </el-table-column>
                  <el-table-column label="知识名称"
                                   min-width="180"
                                   prop="name">
                    <template slot-scope="scope">
                      <span v-html="scope.row.name"></span>
                    </template>
                  </el-table-column>
                  <el-table-column label="所属知识库"
                                   min-width="100"
                                   prop="knowledgeLibName" v-if="libStatus"></el-table-column>
                  <el-table-column label="厂家"
                                   min-width="100"
                                   prop="drugInfoLibCompany" v-if="drugInfoLibStatus"
                                   show-overflow-tooltip></el-table-column>
                  <el-table-column label="来源"
                                   min-width="100"
                                   prop="drugInfoLibSource" v-if="drugInfoLibStatus"
                                   show-overflow-tooltip></el-table-column>
                  <el-table-column label="剩余天数"
                                   min-width="100"
                                   prop="num"></el-table-column>
                  <el-table-column label="完成字数"
                                   min-width="80"
                                   prop="wordsCount" v-if="wordStatus"></el-table-column>
                  <el-table-column label="任务类型"
                                   min-width="80"
                                   prop="type">
                    <template slot-scope="scope">
                      <span v-text="CONST.TASK_ITEM_STATUS_VO.find(item => item.value === scope.row.type).label"></span>
                    </template>
                  </el-table-column>
                  <el-table-column label="任务状态" prop="status" width="200" :show-overflow-tooltip="false">
                    <template slot-scope="scope">
                      <span style="color: #FF8C00" v-if="0 === scope.row.status ">未提交</span>
                      <span v-else-if="1 === scope.row.status">初审中</span>
                      <span v-else-if="4 === scope.row.status">复审中</span>
                      <span v-else-if="6 === scope.row.status">终审中</span>
                      <span v-else-if="2 === scope.row.status ">审核通过</span>
                      <span v-else-if="8 === scope.row.status ">已发布</span>
                      <span style="color: red" v-else-if="scope.row.status === 3">
                  初审驳回
                  <el-popover
                    :content="scope.row.reject"
                    trigger="hover">
                    <el-button slot="reference" style="margin-left: 10px" type="text"><a style="color: #EC0000">详情</a><i
                      class="el-icon-warning-outline el-icon--right" style="color: #EC0000"></i></el-button>
                  </el-popover>
                </span>
                      <span style="color: red" v-else-if="scope.row.status === 5">
                  复审驳回
                  <el-popover
                    :content="scope.row.reject"
                    trigger="hover">
                    <el-button slot="reference" style="margin-left: 10px" type="text"><a style="color: #EC0000">详情</a><i
                      class="el-icon-warning-outline el-icon--right" style="color: #EC0000"></i></el-button>
                  </el-popover>
                </span>
                      <span style="color: red" v-else-if="scope.row.status === 7">
                  终审驳回
                  <el-popover
                    :content="scope.row.reject"
                    trigger="hover">
                    <el-button slot="reference" style="margin-left: 10px" type="text"><a style="color: #EC0000">详情</a><i
                      class="el-icon-warning-outline el-icon--right" style="color: #EC0000"></i></el-button>
                  </el-popover>
                </span>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作"
                                   min-width="150">
                    <template slot-scope="scope">
                      <span><el-link
                        @click.prevent="editById(scope.row)"
                        type="primary"
                        v-if="0 === scope.row.status|| 3 === scope.row.status">编辑</el-link></span>
                      <span><el-link
                        @click.prevent="detailById(scope.row.knowledgeId,scope.row.systemType,scope.row.status)"
                        type="primary"
                        v-if="scope.row.knowledgeId">查看</el-link></span>
                      <span v-if="scope.row.type === 1"><el-link
                        @click.prevent="delById(scope.row.id, scope.row.knowledgeId, scope.row.systemType)"
                        type="danger">删除</el-link></span>
                    </template>
                  </el-table-column>
                </el-table>
              </el-col>
            </el-row>
            <el-row>
              <el-pagination :page-size="pageSize"
                             :total="totalNum"
                             @current-change="handleCurrentChange"
                             background
                             :current-page="currentPage"
                             :page-sizes="[5, 10, 15, 20, 50, 100]"
                             layout="total, sizes, prev, pager, next, jumper"
                             style="text-align: right;margin-top: 10px"
                             @size-change="handleSizeChange"
                             v-if="multiplePages">
              </el-pagination>
            </el-row>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import MenuItem from "../../common/MenuItem";
import PreviewDialog from "../../calculator/exportModel/PreviewDialog";
import EditTaskItemDialog from "../EditTaskItemDialog";

export default {
  name: "AllTaskEditTable",
  props: {
    system: String,
    taskItemId: String,
    taskItemName: String,
    taskItemType: String,
    taskItemStatus: String,
  },
  components: {
    MenuItem,
    PreviewDialog,
    EditTaskItemDialog
  },
  data() {
    return {
      previewDialogVisible: false,
      medicalCalculatorData: [],
      calculatorSore: [],
      describeContent: '',
      fields: [],
      cntFormulaType: 1,
      items: [],
      tableData: [],
      tableHeight: 0,
      multipleSelection: '',
      totalNum: 0,
      currentPage: 1, // 第几页
      pageSize: 10, // 每页显示的数据个数
      multiplePages: true,
      appendIcon: "el-icon-caret-bottom",
      showIcon: "el-icon-caret-bottom",
      showAdvance: false,
      itemOptions: [],
      scienceItemOptions: [],
      knowledgeLibOptions: [],
      belongingItems: "",
      scienceItems: "",
      radioStatus: '',
      cascadeProps: {multiple: false},
      name: "",
      createdTime: '',
      newEnable: '',
      knowledgeLibName: '',
      totalEnable: '',
      uploadEnable: '',
      libEnable: '',
      libStatus: true,
      wordStatus: true,
      drugInfoLibStatus: false,
      startTime: '',
      endTime: '',
      num: '',
      selected: false,
      itemId: '',
      itemName: '',
      showSelectKLibDialog: false,
      knowledgeLibList: [],
      batchEnable: '',
      taskType: '',
      auditLevel: '',
      knowledgeLibId: '',
      systemType: '',
      taskListHeight: 0,
      nameTaskItem: '',
      itemType: '',
      itemStatus: '',
      drugInfoLibCompany: '',
      taskCompleteData: [],
      showCompleteData: false,
      finishItemId: '',
      statusEnable: '',
      statusReleasedEnable: 'none'
    }
  },
  methods: {
    handleCurrentChange: function (val) {
      this.currentPage = val;
      if (this.finishItemId) {
        this.getFinishTableData(this.finishItemId)
      } else {
        this.getTableData(this.itemId);
      }
    },
    newTaskItem: function () {
      let tempTaskItem = {
        taskId: this.itemId,
        knowledgeId: '',
        name: '',
        type: 1,
        editor: this.$store.state.user.userName,
        wordsCount: 0,
        firstAuditor: '',
        secondAuditor: '',
        thirdAuditor: '',
        status: 0,
        remark: '',
        systemType: this.systemType,
        knowledgeLibId: this.knowledgeLibId,
        auditLevel: this.auditLevel
      }
      this.$refs.editTaskItemDialog.title = '新建知识'
      this.$refs.editTaskItemDialog.taskItem = tempTaskItem
      this.$refs.editTaskItemDialog.visible = true

    },
    valueChange: function () {
      this.currentPage = 1, // 第几页
        this.pageSize = 10 // 每页显示的数据个数
      if (this.finishItemId) {
        this.getFinishTableData(this.finishItemId)
      } else {
        this.getTableData(this.itemId);
      }
    },
    refreshList(item) {
      this.finishItemId = ''
      this.statusEnable = ''
      this.statusReleasedEnable = 'none'
      this.setAllItemsUnselected();
      this.setSelectedItem(item)
      if (this.knowledgeLibId != CONST.DRUG_INFO_LIB_ID) {
        this.drugInfoLibCompany = '';
      }
      this.currentPage = 1, // 第几页
        this.pageSize = 10, // 每页显示的数据个数
        this.getTableData(item.id)
    },
    setAllItemsUnselected() {
      this.items.forEach(item => {
        item.selected = false;
      });
    },
    refreshFinishList(item) {
      this.statusEnable = 'none'
      this.statusReleasedEnable = ''
      this.finishItemId = item.id
      this.knowledgeLibId = item.knowledgeLibId
      this.setAllItemsFinishUnselected();
      this.taskCompleteData.forEach(selectItem => {
        if (selectItem.id === item.id) {
          selectItem.selected = true;
          if (selectItem.selected = true) {
            this.items.forEach(item => {
              item.selected = false;
            });
          }
        }
      });
      if (this.knowledgeLibId != CONST.DRUG_INFO_LIB_ID) {
        this.drugInfoLibCompany = '';
      }
      this.currentPage = 1, // 第几页
        this.pageSize = 10, // 每页显示的数据个数
        this.getFinishTableData(item.id)
    },
    setAllItemsFinishUnselected() {
      this.taskCompleteData.forEach(item => {
        item.selected = false;
      });
    },

    setSelectedItem(selectedItem) {
      this.itemId = selectedItem.id
      this.itemName = selectedItem.name
      this.knowledgeLibId = selectedItem.knowledgeLibId
      this.auditLevel = selectedItem.auditLevel
      this.systemType = selectedItem.systemType
      if (selectedItem.enableCreate === 0) {
        this.newEnable = 'none'
        this.totalEnable = ''
      } else {
        this.newEnable = ''
        this.totalEnable = 'none'
      }
      this.items.forEach(item => {
        if (item.id === selectedItem.id) {
          item.selected = true;
          if (item.selected = true) {
            this.taskCompleteData.forEach(item => {
              item.selected = false;
            });
          }
        }
      });
    },
    searchEnterFun(e) {
      const keyCode = window.event ? e.keyCode : e.which;
      console.log("回车搜索", keyCode, e);
      if (keyCode === 13) {
        this.currentPage = 1;
        if (this.finishItemId) {
          this.getFinishTableData(this.finishItemId)
        } else {
          this.getTableData(this.itemId);
        }
      }
    },
    uploadFile: function () {
      console.log(this.itemId)
      this.axios.get('/pmph/action/file/uploadFile', {
        params: {
          taskId: this.itemId
        },
        headers: {
          'Content-Type': 'application/json; application/octet-stream'
        },
        responseType: 'blob'
      }).then((response) => {
        if (response.data.size === 0) {
          this.$message.warning("该任务下没有需要下载的文件")
          return;
        }
        let url = window.URL.createObjectURL(new Blob([response.data], {type: "application/octet-stream"}));
        let link = document.createElement('a');
        link.style.display = 'none';
        link.href = url;
        link.setAttribute('download', this.itemName + '.zip');
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link); //下载完成移除元素
        window.URL.revokeObjectURL(url); //释放blob对

      });
    },
    editById: function (row) {
      row.editOrAudit = 'edit'
      this.$store.commit('setTaskItem', row)
      if (row.systemType === 'knowledge') {
        this.$router.push('/knowledge/edit')
      } else if (row.systemType === 'calc') {
        if (row.knowledgeId) {
          this.$router.push({
              path: '/formula/editor',
              query: {
                id: row.knowledgeId,
                taskItemId: row.id,
                auditLevel: row.auditLevel,
                enableCreate: row.type,
                itemName: row.name,
                nameSuggestion: JSON.stringify(row.nameSuggestion),
                status: row.status,
              }
            }
          )
        } else {
          this.$router.push({
            path: "/formula/editor",
            query: {
              taskItemId: row.id,
              auditLevel: row.auditLevel,
              enableCreate: row.type,
              itemName: row.name,
              nameSuggestion: JSON.stringify(row.nameSuggestion),
              status: row.status,
            }
          })
        }
      } else if (row.systemType === 'flowchart') {
        if (row.knowledgeId) {
          let routeUrl = this.$router.resolve({
            path: "/knowledgeLib/MakeFlowChart",
            query: {
              id: row.knowledgeId,
              showStatus: 'new',
              taskItemId: row.id,
              auditLevel: row.auditLevel,
              enableCreate: row.type,
              itemName: row.name,
            },
          });
          window.open(routeUrl.href, "_blank");
        } else {
          let routeUrl = this.$router.resolve({
            path: "/knowledgeLib/MakeFlowChart",
            query: {
              showStatus: 'new',
              taskItemId: row.id,
              auditLevel: row.auditLevel,
              enableCreate: row.type,
              itemName: row.name,
            }
          });
          window.open(routeUrl.href, "_blank");
        }
      }
    },
    detailById: function (id, systemType, status) {
      if (systemType === 'knowledge') {
        if (status === 8) {
          this.$store.commit('setKnowledgeDetailId', id)
          this.$store.commit('setKnowledgeDetailStatus', 'published')
          this.$store.commit('showKnowledgeDetail')
        } else {
          this.$store.commit('setKnowledgeDetailId', id)
          this.$store.commit('setKnowledgeDetailStatus', 'unpublished')
          this.$store.commit('showKnowledgeDetail')
        }

      } else if (systemType === 'calc') {
        let that = this
        this.axios.get('/pmph/action/medicalCalculator/selectDataById', {
          params: {
            id: id,
          }
        }).then((response) => {
          that.medicalCalculatorData = response.data.medicalCalculatorData
          that.calculatorSore = response.data.calculatorSore
          that.describeContent = response.data.describeContent
          if (!this.describeContent) {
            this.describeContent = '无'
          }
          that.fields = response.data.fields
          for (let i = 0; i < that.fields.length; i++) {
            if (that.fields[i].kind === 1) {
              that.fields[i].property = JSON.parse(that.fields[i].property)
            }
          }
          that.cntFormulaType = response.data.type
          that.previewDialogVisible = true
        });
      } else if (systemType === 'flowchart') {
        let routeUrl = this.$router.resolve({
          path: "/flowchart/mobileViewFlowChart",
          query: {id: id},
        });
        window.open(routeUrl.href, "_blank");
      }
    },
    async delById(taskItemId, knowledgeId, systemType) {
      let tip = '您确定要删除该子任务吗？删除后对应的已经编辑的内容都将一并被删除';
      if (systemType === 'knowledge') {
        await this.axios.get("/pmph/action/knowledgeLib/selectBindingKnowledge", {
          params: {
            knowledgeId: knowledgeId
          }
        }).then((res) => {
          // bindingKnowledgeArray = [{knowledgeFieldId: "", knowledgeFieldName: "", knowledgeId: "", knowledgeName: "", knowledgeLibId: "", knowledgeLibName: ""}]
          let bindingKnowledgeArray = res.data
          if (bindingKnowledgeArray.length !== 0) {
            let bingKnowledge = ""
            bindingKnowledgeArray.forEach(item => {
              bingKnowledge += ("【" + item.knowledgeLibName + " / " + item.knowledgeName + "】")
            })
            tip = "本知识绑定了" + bindingKnowledgeArray.length + "条知识：" + bingKnowledge + "，删除后该知识也会从绑定知识的相应字段删除且不可恢复，是否确认删除？";
          }
        })
      }
      this.$confirm(tip, '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.axios.get("/pmph/action/task/delById", {
          params: {
            id: taskItemId,
            knowledgeId: knowledgeId,
            systemType: systemType
          }
        }).then(() => {
          this.getTableData(this.itemId);
        })
      })
    },
    switchAppend: function () {
      if (this.showAdvance) {
        this.showAdvance = false;
        this.appendIcon = "el-icon-caret-bottom";
      } else {
        this.showAdvance = true;
        this.appendIcon = "el-icon-caret-top";
      }
    },
    showData() {
      if (this.showCompleteData) {
        this.showCompleteData = false;
        this.showIcon = "el-icon-caret-left";
      } else {
        this.showCompleteData = true;
        this.showIcon = "el-icon-caret-bottom";
      }
    },
    getTableData: function (id) {
      if (this.knowledgeLibId === CONST.DRUG_INFO_LIB_ID) {
        this.drugInfoLibStatus = true;
      } else {
        this.drugInfoLibStatus = false;
      }
      this.axios.get('/pmph/action/task/selectTableData', {
        params: {
          currentPage: this.currentPage - 1,
          pageSize: this.pageSize,
          taskId: id,
          status: this.radioStatus,
          name: this.name,
          libId: this.knowledgeLibName,
          taskType: this.taskType,
          drugInfoLibCompany: this.drugInfoLibCompany
        }
      }).then((response) => {
        this.noData = response.data.totalNum <= 0;
        this.tableData = response.data.tableData;
        this.totalNum = response.data.totalNum;
        if (this.tableData.length > 0) {
          this.startTime = response.data.tableData[0].startDate,
            this.endTime = response.data.tableData[0].endDate
        }
        for (let i = 0; i < this.tableData.length; i++) {
          if (this.tableData[0].systemType === 'flowchart') {
            this.libStatus = false
            this.wordStatus = false
          } else if (this.tableData[0].systemType === 'calc') {
            this.libStatus = false
          } else {
            this.libStatus = true
            this.wordStatus = true
          }
        }
      })
    },
    getFinishTableData(id) {
      if (this.knowledgeLibId === CONST.DRUG_INFO_LIB_ID) {
        this.drugInfoLibStatus = true;
      } else {
        this.drugInfoLibStatus = false;
      }
      this.axios.get('/pmph/action/task/selectFinishEditTaskList', {
        params: {
          page: this.currentPage,
          size: this.pageSize,
          taskId: id,
          status: this.radioStatus,
          name: this.name,
          libId: this.knowledgeLibName,
          taskType: this.taskType,
          drugInfoLibCompany: this.drugInfoLibCompany
        }
      }).then((response) => {
        this.noData = response.data.totalNum <= 0;
        this.tableData = response.data.tableData;
        this.totalNum = response.data.totalNum;

      })
    },
    advanceCancel: function () {
      this.showAdvance = false;
    },
    reset: function () {
      this.name = '';
      this.taskType = '';
      this.drugInfoLibCompany = '';
    },
    advanceConfirm: function () {
      this.currentPage = 1 // 第几页
      this.pageSize = 5// 每页显示的数据个数
      if (this.finishItemId) {
        this.getFinishTableData(this.finishItemId)
      } else {
        this.getTableData(this.itemId);
      }
      this.showAdvance = false;
    },
    // 批量提交
    batchSubmit: function () {
      // 搜索当前条件下待提交的数据
      this.axios.get('/pmph/action/task/selectNoCommitKnowledge', {
        params: {
          taskId: this.itemId,
          name: this.name
        }
      }).then((response) => {
        if (response.data == null) {
          this.$message.warning("当前条件下没有未提交的知识");
        } else {
          this.$confirm("您确认要提交当前条件下所有未提交知识，待提交知识共" + response.data.length + "条", '提示', {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            this.axios.get('/pmph/action/task/batchSubmit', {
              params: {
                taskId: this.itemId,
                name: this.name
              }
            }).then((response) => {
              this.getTableData(this.itemId);
            })
          })
        }
      }).catch((error) => {
        console.error(error);
        this.$message.error("批量提交失败");
      });
    },
    handleSizeChange(value) {
      this.pageSize = value
      this.getTableData(this.itemId)
    },
    getTaskList() {
      if (this.system === 'all') {
        this.batchEnable = 'none'
      }
      this.axios.get('/pmph/action/task/selectTaskList', {
        params: {
          systemType: this.system === 'all' ? '' : this.system
        }
      }).then((response) => {
        this.items = response.data.result;
        this.taskCompleteData = response.data.completeResult;
        if (this.items.length === 0) {
          return
        }
        if (this.taskItemId) {
          this.itemId = this.taskItemId
          if (UTIL.isNotEmpty(this.taskItemName)) {
            this.name = this.taskItemName
          }
          if (this.taskItemStatus) {
            this.radioStatus = this.taskItemStatus
          }
          this.knowledgeLibId = this.knowledgeLibId
          let crtTask = this.items.find(item => item.id === this.taskItemId)
          if (crtTask.enableCreate === 0) {
            this.newEnable = 'none'
            this.totalEnable = ''
          } else {
            this.newEnable = ''
            this.totalEnable = 'none'
          }
          this.itemName = crtTask.name
          crtTask.selected = true
        } else {
          this.items[0].selected = true
          this.itemId = this.items[0].id
          this.itemName = this.items[0].name
          this.knowledgeLibId = this.items[0].knowledgeLibId
          this.auditLevel = this.items[0].auditLevel
          this.systemType = this.items[0].systemType
          this.statusReleasedEnable = 'none'

          if (this.items[0].enableCreate === 0) {
            this.newEnable = 'none'
            this.totalEnable = ''
          } else {
            this.newEnable = ''
            this.totalEnable = 'none'
          }
        }
        this.getTableData(this.itemId)
      })
    },
    visibilitychange() {
      if (document.visibilityState !== "hidden") {
        this.getTableData(this.itemId)
        if (this.itemId) {
          this.taskItemId = this.itemId
          this.getTaskList()
        }
      }
    },
    addVisibilityChange() {
      window.addEventListener("visibilitychange", this.visibilitychange)
    },
    removeVisibilityChange() {
      window.removeEventListener("visibilitychange", this.visibilitychange)

    }
  },
  activated() {
    this.addVisibilityChange()
    if (this.$route.meta.isUseCache) {
      this.getTableData(this.itemId)
      if (this.itemId) {
        this.taskItemId = this.itemId
        this.getTaskList()
      }
    } else {
      this.getTaskList()
    }
  },

  created() {
    this.addVisibilityChange()
    this.removeVisibilityChange()
    this.getTaskList()
    this.tableHeight = CONST.WORKSPACE_HEIGHT - 195
    this.taskListHeight = CONST.WORKSPACE_HEIGHT - 70
  },
}
</script>

<style scoped>
.inline-block {
  display: inline-block;
  margin-left: 10px;
  color: #666666;
  font-size: 14px;
}

/deep/ .el-scrollbar__wrap {
  overflow-x: hidden;
}

.cursor {
  cursor: pointer;
}
</style>
